package com.yonyou.cyxdms.sysAuth.service.controller.manage.company;

import com.yonyou.cyx.framework.controller.base.BaseController;
import com.yonyou.cyx.framework.util.bean.ApplicationContextHelper;
import com.yonyou.cyxdms.framework.bean.dto.user_info.LoginInfoDto;
import com.yonyou.cyxdms.sysAuth.service.constants.StringUtil;
import com.yonyou.cyxdms.sysAuth.service.service.manage.company.DealerBasicinfoService;
import com.yonyou.cyxdms.sysAuth.service.vo.companyorg.DealerchannelVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Api(description = "经销商信息管理", tags = {"DealerBasicinfoController"})
@RestController
public class DealerBasicinfoController extends BaseController {

    @Autowired
    private DealerBasicinfoService dealerService;

    /**
     * 查询当前经销商信息(经销商渠道表)
     * mxingjian 20190709
     *
     * @return
     */
    @RequestMapping(value = "/dealer/getDealerChannelByCode", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(value = "userId", name = "userId", required = true, dataType = "string", paramType = "header")
    })
    public DealerchannelVO getDealerChannelByCode() {
        LoginInfoDto loginInfo = ApplicationContextHelper.getBeanByType(LoginInfoDto.class);
        return dealerService.getDealerChannelByCode(loginInfo.getCompanyId(),loginInfo.getAppId());
    }

    /**
     * 查询除了自己的所有经销商
     *
     * @param
     * @return java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
     * @author renwd
     * @since 2019/7/9
     */
    @ApiOperation(value = "查询除了自己的所有经销商")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "userId", name = "userId", required = true, dataType = "string", paramType = "header")
    })
    @GetMapping("/dealersExceptSelf")
    public List<Map<String, Object>> getDealerExceptSelf() {
        return dealerService.getDealerExceptSelf();
    }


    /**
     *  获取经销商基本信息
     *
     * @author dengqiang
     * @since 2019/7/25
     */
    @GetMapping(value = "/dealer")
    @ResponseBody
    public Map<String,Object> getDealerBasicinfoById() {
        Map<String,Object> dealerMap = dealerService.getDealerBasicinfo();
        Map<String,Object> resMap=new HashMap<>();//将key值变驼峰命名
        for (Map.Entry entry :dealerMap.entrySet()) {
            Object key = entry.getKey();
            resMap.put(StringUtil.underlineToCamel(key.toString()), dealerMap.get(key));
        }
        return resMap;
    }


}



